#Region " Imports "

Imports System.Configuration.ConfigurationManager
Imports BlazeApps.Library.Messaging
Imports BlazeApps.Library.Forum

#End Region

Partial Class Usercontrols_MasterPage_LoginUserInfo
    Inherits UserControlBase

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim ArrayNames() As String = {HttpContext.Current.User.Identity.Name}
        Dim Password As New Security
        Dim MessageCount As New Inbox
        Dim PostCount As New ForumList

        If HttpContext.Current.User.Identity.IsAuthenticated = True And IsBanned() Then
            Response.Redirect(String.Format("{0}.aspx?pid=sec_banned&popup=1", AppPage))
        Else
            If HttpContext.Current.User.Identity.AuthenticationType = "NTLM" Then

                Me.uxLoginStatus.Visible = False
                Me.uxLoginStatus.Enabled = False

                If IsNothing(Membership.GetUser(HttpContext.Current.User.Identity.Name)) Then
                    Membership.CreateUser(HttpContext.Current.User.Identity.Name, Membership.GeneratePassword(6, 2), HttpContext.Current.User.Identity.Name.ToString.Trim & AppSettings("EmailDomain"))
                End If

                If HttpContext.Current.User.Identity.IsAuthenticated = True Then
                    Me.uxUserInfoLabel.Text = String.Format("<a href=""{0}.aspx?pid=cp_profile"">{1}</a>", AppPage, HttpContext.Current.User.Identity.Name.Trim)
                End If

            Else
                If HttpContext.Current.User.Identity.IsAuthenticated = True Then
                    Me.uxUserInfoLabel.Text = String.Format("<a href=""{0}.aspx?pid=cp_profile"">{1}</a> | ", AppPage, HttpContext.Current.User.Identity.Name.Trim)
                Else
                    Me.uxUserInfoLabel.Text = String.Format("<a href=""{0}.aspx?pid=sec_newuser"">{1}</a> | ", AppPage, Resources.Resource.Register.ToString)
                End If
            End If

            If HttpContext.Current.User.Identity.IsAuthenticated = True Then
                If Roles.IsUserInRole(HttpContext.Current.User.Identity.Name, "member") = False Then
                    Roles.AddUsersToRole(ArrayNames, "member")
                End If

                If Me.Page.IsPostBack = False Then

                    Me.uxEmailImageButton.Enabled = True
                    Me.uxEmailImageButton.Visible = True
                    Me.uxInboxCountLabel.Text = String.Format(" ({0})", MessageCount.GetInboxCount(CurrentUserID))

                    If Roles.IsUserInRole(HttpContext.Current.User.Identity.Name, "moderator") = True OrElse Roles.IsUserInRole(HttpContext.Current.User.Identity.Name, "admin") = True Then
                        Dim Count As Integer = PostCount.GetForumPendingPostsCount(CurrentUserID)

                        If Count > 0 Then
                            DisplayPendingPostItems(True)
                            Me.uxPendingPostCountLabel.Text = String.Format(" ({0})", Count)
                        Else
                            DisplayPendingPostItems(False)
                        End If
                    End If

                End If

            End If

        End If

    End Sub

    Protected Sub uxEmailImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles uxEmailImageButton.Click
        Response.Redirect(String.Format("{0}.aspx?pid=msg_messagesystem", AppPage))
    End Sub

    Protected Sub uxPendingPostLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxPendingPostLinkButton.Click
        Response.Redirect(String.Format("{0}.aspx?pid=for_pendingposts", AppPage))
    End Sub

    Private Sub DisplayPendingPostItems(ByVal Visible As Boolean)
        Me.uxPendingPostLinkButton.Enabled = Visible
        Me.uxPendingPostLinkButton.Visible = Visible
        Me.uxPendingPostCountLabel.Enabled = Visible
        Me.uxPendingPostCountLabel.Visible = Visible
    End Sub

End Class
